package com.dream21th.admin.controller;

import com.dream21th.admin.entity.SysConfigEntity;
import com.dream21th.admin.service.SysConfigService;
import com.dream21th.admin.utils.ComResp;
import com.dream21th.admin.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;


@RestController
@RequestMapping("/sys/config")
public class SysConfigController {
	@Autowired
	private SysConfigService sysConfigService;

	/**
	 * 所有配置列表
	 */
	@GetMapping("/list")
	public ComResp list(@RequestParam Map<String, Object> params){
		PageUtils page = sysConfigService.queryPage(params);

		return ComResp.ok().put("page", page);
	}


	/**
	 * 配置信息
	 */
	@GetMapping("/info/{id}")
	public ComResp info(@PathVariable("id") Long id){
		SysConfigEntity config = sysConfigService.getById(id);

		return ComResp.ok().put("config", config);
	}

	/**
	 * 保存配置
	 */
	@PostMapping("/save")
	public ComResp save(@RequestBody SysConfigEntity config){

		sysConfigService.saveConfig(config);

		return ComResp.ok();
	}

	/**
	 * 修改配置
	 */
	@PostMapping("/update")
	public ComResp update(@RequestBody SysConfigEntity config){
		sysConfigService.update(config);

		return ComResp.ok();
	}

	/**
	 * 删除配置
	 */
	@PostMapping("/delete")
	public ComResp delete(@RequestBody Long[] ids){
		sysConfigService.deleteBatch(ids);

		return ComResp.ok();
	}

}
